import {axios} from '../utils/request'
import {PRODUCT_MODULE} from './_prefix'


type productCreateInfo = {
    name : string
    category : number
    photoUrl : string[]
    quantity : number
    price : number
}

type productQuantity = {
    ID : number
    newQuantity : number
}

type productSearch = {
    name ?: string
    categories ?: string
    max_price ?: number|string
    min_price ?: number|string
    page : number
    pageSize : number
}

//获取指定id的商品信息
export const productInfo = (ProductId : number) => {
    return axios.post(`${PRODUCT_MODULE}/info`, null, {params: {id : ProductId}})
        .then(res => {
            return res
        })
}

//创建商品
export const productCreate = (productCreateInfo : productCreateInfo) => {
    return axios.post(`${PRODUCT_MODULE}/create`,productCreateInfo,
        {headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res
        })
}

//增删库存
export const changeQuantity = (productQuantity: productQuantity) =>{
    return axios.post(`${PRODUCT_MODULE}/change_quantity`,null,{params:productQuantity})
}

//获取评论
export const getComment = (productId : number) =>{
    return axios.post(`${PRODUCT_MODULE}/get_comment`,null , {params:{id : productId}})
}

//根据搜索条件获取商品信息
export const getSearchProduct = (productSearch : productSearch) =>{
    return axios.post(`${PRODUCT_MODULE}/search`,null , {params:productSearch})
}